﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PPAP.BO;
using System.Data;
using PPAP.Model;

namespace PPAP.Web.Part
{
    public partial class InapplicableSet : PageBase
    {
        AttachmentTypeBO typebo = new AttachmentTypeBO();
        InapplicableBO ibo = new InapplicableBO();
        PPARBO pbo = new PPARBO();
        LogBO lbo = new LogBO();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["RID"] != null)
                {
                    DataSet ds = typebo.GetList("");
                    LoadType(ds);
                    DataSet ids = ibo.GetList(" pparid="+Request.QueryString["RID"].ToString());
                    LoadFileSet(ids);
                }
            }
        }


        /// <summary>
        /// 加载附件类型
        /// </summary>
        /// <param name="ds"></param>
        private void LoadType(DataSet ds)
        {
            string TypeName = "";
            int ID = 0;
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                TypeName = dr["ATTACHMENTTYPE"].ToString();
                ID = int.Parse(dr["rownum"].ToString());
                switch (ID)
                {
                    case 1:
                        lblType1.Text = TypeName;
                        break;
                    case 2:
                        lblType2.Text = TypeName;
                        break;
                    case 3:
                        lblType3.Text = TypeName;
                        break;
                    case 4:
                        lblType4.Text = TypeName;
                        break;
                    case 5:
                        lblType5.Text = TypeName;
                        break;
                    case 6:
                        lblType6.Text = TypeName;
                        break;
                    case 7:
                        lblType7.Text = TypeName;
                        break;
                    case 8:
                        lblType8.Text = TypeName;
                        break;
                    case 9:
                        lblType9.Text = TypeName;
                        break;
                    case 10:
                        lblType10.Text = TypeName;
                        break;
                    case 11:
                        lblType11.Text = TypeName;
                        break;
                    case 12:
                        lblType12.Text = TypeName;
                        break;
                    case 13:
                        lblType13.Text = TypeName;
                        break;
                    case 14:
                        lblType14.Text = TypeName;
                        break;
                    case 15:
                        lblType15.Text = TypeName;
                        break;
                    case 16:
                        lblType16.Text = TypeName;
                        break;
                    case 17:
                        lblType17.Text = TypeName;
                        break;
                    case 18:
                        lblType18.Text = TypeName;
                        break;
                    case 19:
                        lblType19.Text = TypeName;
                        break;
                    case 20:
                        lblType20.Text = TypeName;
                        break;
                    case 21:
                        lblType21.Text = TypeName;
                        break;
                    case 22:
                        lblType22.Text = TypeName;
                        break;
                    case 23:
                        lblType23.Text = TypeName;
                        break;
                    case 24:
                        lblType24.Text = TypeName;
                        break;
                    case 25:
                        lblType25.Text = TypeName;
                        break;
                    case 26:
                        lblType26.Text = TypeName;
                        break;
                    case 27:
                        lblType27.Text = TypeName;
                        break;
                    case 28:
                        lblType28.Text = TypeName;
                        break;
                    //case 29:
                    //    lblType29.Text = TypeName;
                    //    break;
                    //case 30:
                    //    lblType30.Text = TypeName;
                    //    break;
                    default:
                        break;
                }
            }
        }

        /// <summary>
        /// 加载不需要上传的附件类型
        /// </summary>
        /// <param name="ds"></param>
        private void LoadFileSet(DataSet ds)
        {
            int ID = 0;
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                ID = int.Parse(dr["sx"].ToString());
                switch (ID)
                {
                    case 1:
                        CheckBox1.Checked = true;
                        break;
                    case 2:
                        CheckBox2.Checked = true;
                        break;
                    case 3:
                        CheckBox3.Checked = true;
                        break;
                    case 4:
                        CheckBox4.Checked = true;
                        break;
                    case 5:
                        CheckBox5.Checked = true;
                        break;
                    case 6:
                        CheckBox6.Checked = true;
                        break;
                    case 7:
                        CheckBox7.Checked = true;
                        break;
                    case 8:
                        CheckBox8.Checked = true;
                        break;
                    case 9:
                        CheckBox9.Checked = true;
                        break;
                    case 10:
                        CheckBox10.Checked = true;
                        break;
                    case 11:
                        CheckBox11.Checked = true;
                        break;
                    case 12:
                        CheckBox12.Checked = true;
                        break;
                    case 13:
                        CheckBox13.Checked = true;
                        break;
                    case 14:
                        CheckBox14.Checked = true;
                        break;
                    case 15:
                        CheckBox15.Checked = true;
                        break;
                    case 16:
                        CheckBox16.Checked = true;
                        break;
                    case 17:
                        CheckBox17.Checked = true;
                        break;
                    case 18:
                        CheckBox18.Checked = true;
                        break;
                    case 19:
                        CheckBox19.Checked = true;
                        break;
                    case 20:
                        CheckBox20.Checked = true;
                        break;
                    case 21:
                        CheckBox21.Checked = true;
                        break;
                    case 22:
                        CheckBox22.Checked = true;
                        break;
                    case 23:
                        CheckBox23.Checked = true;
                        break;
                    case 24:
                        CheckBox24.Checked = true;
                        break;
                    case 25:
                        CheckBox25.Checked = true;
                        break;
                    case 26:
                        CheckBox26.Checked = true;
                        break;
                    case 27:
                        CheckBox27.Checked = true;
                        break;
                    case 28:
                        CheckBox28.Checked = true;
                        break;
                    //case 29:
                    //    CheckBox29.Checked = true;
                    //    break;
                    //case 30:
                    //    CheckBox30.Checked = true;
                    //    break;
                    default:
                        break;
                }
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["RID"] != null)
            {
                ibo.Delete(int.Parse(Request.QueryString["RID"].ToString()));
                Model.Inapplicable app = new Model.Inapplicable();
                app.CREATETIME = DateTime.Now;
                app.CREATEUSER = CurrentUser.Id;
                app.PPARID = int.Parse(Request.QueryString["RID"].ToString());
                if (CheckBox1.Checked)
                {
                    app.NO = 1;
                    ibo.Add(app);
                }
                if (CheckBox2.Checked)
                {
                    app.NO = 2;
                    ibo.Add(app);
                }
                if (CheckBox3.Checked)
                {
                    app.NO = 3;
                    ibo.Add(app);
                }
                if (CheckBox4.Checked)
                {
                    app.NO = 4;
                    ibo.Add(app);
                }
                if (CheckBox5.Checked)
                {
                    app.NO = 5;
                    ibo.Add(app);
                }
                if (CheckBox6.Checked)
                {
                    app.NO = 6;
                    ibo.Add(app);
                }
                if (CheckBox7.Checked)
                {
                    app.NO = 7;
                    ibo.Add(app);
                }
                if (CheckBox8.Checked)
                {
                    app.NO = 8;
                    ibo.Add(app);
                }
                if (CheckBox9.Checked)
                {
                    app.NO = 9;
                    ibo.Add(app);
                }
                if (CheckBox10.Checked)
                {
                    app.NO = 10;
                    ibo.Add(app);
                }
                if (CheckBox11.Checked)
                {
                    app.NO = 31;
                    ibo.Add(app);
                }
                if (CheckBox12.Checked)
                {
                    app.NO = 11;
                    ibo.Add(app);
                }
                if (CheckBox13.Checked)
                {
                    app.NO = 12;
                    ibo.Add(app);
                }
                if (CheckBox14.Checked)
                {
                    app.NO = 13;
                    ibo.Add(app);
                }
                if (CheckBox15.Checked)
                {
                    app.NO = 14;
                    ibo.Add(app);
                }
                if (CheckBox16.Checked)
                {
                    app.NO = 15;
                    ibo.Add(app);
                }
                if (CheckBox17.Checked)
                {
                    app.NO = 17;
                    ibo.Add(app);
                }
                if (CheckBox18.Checked)
                {
                    app.NO = 18;
                    ibo.Add(app);
                }
                if (CheckBox19.Checked)
                {
                    app.NO = 19;
                    ibo.Add(app);
                }
                if (CheckBox20.Checked)
                {
                    app.NO = 20;
                    ibo.Add(app);
                }
                if (CheckBox21.Checked)
                {
                    app.NO = 21;
                    ibo.Add(app);
                }
                if (CheckBox22.Checked)
                {
                    app.NO = 22;
                    ibo.Add(app);
                }
                if (CheckBox23.Checked)
                {
                    app.NO = 23;
                    ibo.Add(app);
                }
                if (CheckBox24.Checked)
                {
                    app.NO = 24;
                    ibo.Add(app);
                }
                if (CheckBox25.Checked)
                {
                    app.NO = 25;
                    ibo.Add(app);
                }
                if (CheckBox26.Checked)
                {
                    app.NO = 26;
                    ibo.Add(app);
                }
                if (CheckBox27.Checked)
                {
                    app.NO = 27;
                    ibo.Add(app);
                }
                if (CheckBox28.Checked)
                {
                    app.NO = 29;
                    ibo.Add(app);
                }
                //if (CheckBox29.Checked)
                //{
                //    app.NO = 29;
                //    ibo.Add(app);
                //}
                //if (CheckBox30.Checked)
                //{
                //    app.NO = 30;
                //    ibo.Add(app);
                //}
                pbo.UpdateInapplicable(Request.QueryString["RID"].ToString());
                lbo.WriteLog(CurrentUser.Id, "Set Inapplicable");
                //if (Request.QueryString["type"] != null)
                //{
                //    Response.Write("<script language=javascript>top.frames['menu'].location.reload();</script>");
                //    Response.Write("<script>top.frames['mainFrame'].location='Inapplicable.aspx'</script>");
                //}
                //else
                AlertReflashOpener("save succeed");
            }
        }

    }
}